<template>

    <m-table name="admin-store" :action="action" :search="search" :params="params" ref="table">

        <el-table-column label="昵称" prop="name" />

        <el-table-column label="门头照" width="130">
            <template slot-scope="scope">
                <el-avatar :src="scope.row.avatar" fit="contain"></el-avatar>
            </template>
        </el-table-column>

        <el-table-column label="手机号" prop="phone" />

        <el-table-column label="状态" prop="state">
            <el-link slot-scope="row"  @click="changeAccountState(row.row)" :type="row.row.state == 1 ? 'success' : 'danger' ">{{ getStateName(row.row.state) }}</el-link>
        </el-table-column>
        
        
        <el-table-column label="注册时间" prop="created"  />
    </m-table>

  

</template>

<script>
import request from '@/utils/request'
import { accountState } from '@/config/account'
export default {
    data() {
        return {
            states:accountState,
            search: [
                { icon: 'el-icon-mobile', type: 'like', name: 'name', label: '用户姓名', span: 4, value: '' },
                { icon: 'el-icon-mobile', type: 'like', name: 'phone', label: '联系方式', span: 4, value: '' }
            ],
            action: { remove: false, edit: true, add: true, export: false },
            params:[
                { name: 'id', value: '', hide: true },
                { name: 'name', value: '', label: '门店名' , type:'string'},
                { name: 'avatar', value: '', label: '门店图' , type:'image' , count : 1},
                { name: 'phone', value: '', label: '手机号' , type:'string'},
                { name: 'pwd', value: '', label: '登录密码' , type:'string'},
                { name: 'address', value: '', label: '门店地址' , type:'string'},
                { name: 'state', value: '', label: '状态' , type:'select' , data:accountState},
            ]
        }
    },
    methods:{
        getStateName(e){
            try {
               return  this.states.find(x=>x.id == e).name
            } catch (error) {
                return '未知'
            }
        },
        async changeAccountState(e){

            await request.post(`admin-store/setstate/${e.id}/${e.state}`)

            this.$message.success('操作成功')

            this.$refs.table.reload()
        },
    }
}
</script>